package com.zkingsoft.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.zkingsoft.plugin.util.ResponseUtils;
import com.zkingsoft.pojo.AjaxResult;

/**
 * @description 全局异常处理类
 * @author 姜友瑶
 * @data 2016-06-26
 */
@Service("com.aex.denner.exception.AexMvcExceptionResolver")
public class GlobleExceptionResolver implements HandlerExceptionResolver {

	Logger log = Logger.getLogger(this.getClass());

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		log.warn("系统出现错误:" + ex.getMessage());
		GlobleException globleException = null;
		if (ex instanceof GlobleException) {
			globleException = (GlobleException) ex;
		} else {
			globleException = new GlobleException("系统出现错误请稍后再试！错误信息：" + ex.getMessage());
		}
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_ERR, null, globleException.getMessage());
		ResponseUtils.send(response, result);
		return null;
	}

}
